<template>
  <div class="cont">
    <h1>{{ obj.title }}</h1>
    <div class="user">
      <div class="user">
        <van-image
        class="margin"
        v-if="obj.aut_photo"
        width="1.5rem"
        height="1.5rem"
        round
        fit="cover"
        :src="obj.aut_photo"
      />
      <div class="info">
        <span class="spanTab">{{ obj.aut_name }}</span>
        <span style="color: #ccc" class="spanTab">{{
          obj.pubdate | time
        }}</span>
      </div>
      </div>
      <div class="follow">
        <van-button
          v-if="obj.is_followed"
          round
          type="info"
          size="mini"
          class="margin"
          @click="targetFollowed(obj.aut_id)"
        >
          已关注</van-button
        >
        <van-button
          v-else
          round
          type="info"
          size="mini"
          class="margin"
          @click="targetFollowed(obj.aut_id)"
        >
          + 关注</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { addFollowed, delFollowed } from '@/api/user.js'
export default {
  name: 'like',
  props: ['obj'],
  methods: {
    // 关注或取消关注文章
    async targetFollowed (target) {
      try {
        if (this.obj.is_followed) {
          await delFollowed(target)
        } else {
          await addFollowed({ target })
        }
        this.obj.is_followed = !this.obj.is_followed
      } catch (err) {
        this.$toast('自己不能关注自己')
      }
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.van-nav-bar .van-icon {
  font-size: 40px;
  color: #000;
}
/deep/.van-image {
  img {
    width: 73px;
    height: 73px;
  }
}
/deep/.van-button {
  width: 172px;
  height: 58px;
  font-size: 30px;
}
.cont {
  padding: 0 25px;
  h1 {
    font-size: 40px;
  }
}
.info {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
}
.user {
  font-size: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.margin {
  margin-right: 26px;
}
</style>
